$(function () {
    if (editType != 'info') {
        regValidate(["#_isvBizDataForm"]);
    }
});

function typeChangeEvent() {
    var serviceType = $('#otherServiceType').val();
    if (serviceType == 'html') {
        $('#_lab_mid').css('display', 'inline');
        $('#_div_mid').css('display', 'inline');
    } else {
        $('#_lab_mid').css('display', 'none');
        $('#_div_mid').css('display', 'none');
    }
}

function doIsvBizSave() {
    if(!$("#_isvBizDataForm").valid()) return;//校验不通过
    var data = getFromData('#_isvBizDataForm');
    var sortNum = (!data.sortNum || data.sortNum == '') ? 999 : data.sortNum;
    var postData = {
        isvName : data.isvName,
        bizCode : data.bizCode,
        isvAppId : data.isvAppId,
        sortNum : sortNum,
        remark : data.remark,
        isPlatformCharge : data.isPlatformCharge,
        cashCollectionType : data.cashCollectionType,
        cashPumpingType : data.cashPumpingType,
        cashPumpingFee : data.cashPumpingFee,
        receivingAccountType : data.receivingAccountType,
        receivingAccountNumber : data.receivingAccountNumber,
        receivingMan : data.receivingMan,
        receivingManPhone : data.receivingManPhone,
        otherServiceName : data.otherServiceName,
        otherServiceType : data.otherServiceType,
        otherServiceUrl : data.otherServiceUrl,
        otherServiceDesc : data.otherServiceDesc,
        hasMidPage : data.hasMidPage,
    };
    postData.isvPid = oneIsvBizInfo.isvPid;
    var url = basePath + 'basic/isvBiz/addIsvBiz?t=' + new Date().getTime();
    if (editType == 'edit') {
        postData.id = oneIsvBizInfo.id;
        url = basePath + 'basic/isvBiz/editIsvBiz?t=' + new Date().getTime();
    }
    showLoading();
    $.ajax({
        type: 'post',
        url: url,
        dataType: 'json',
        data: postData,
        success : function (data) {
            hideLoading();
            if (!data) {
                toastr.error(common_save_fail);
                return;
            }
            if (data.isSuccess) {
                toastr.success(common_save_success);
                doBack();
                return;
            }
            if (!data.isSuccess && data.errorCode == 'EXIST') {
                toastr.error('该服务商下已存在此业务');
                return;
            }
            if (!data.isSuccess && data.errorCode == 'EXIST_CODE') {
                toastr.error('该APPID已存在，不能重复添加');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
            return;
        }
    });
}

function doBack() {
    window.location.href = basePath + 'basic/isvBiz/isvBizPage?searchKey=' + oneIsvBizInfo.searchKey + '&t=' + new Date().getTime() + '&isIsvInfoExist=' + searchIsvBizInfo.isIsvInfoExist +
        '&pageNo=' + searchIsvBizInfo.pageNo + '&pageSize=' + searchIsvBizInfo.pageSize + '&searchIsvName=' + searchIsvBizInfo.searchIsvName + '&isvPid=' + searchIsvBizInfo.isvPid;
}

function doCheckDataChange() {
    var data = getFromData('#_isvBizDataForm');
    var checkData = {
        isvName : data.isvName,
        bizCode : data.bizCode,
        isvAppId : data.isvAppId,
        sortNum : data.sortNum,
        remark : data.remark,
        isPlatformCharge : data.isPlatformCharge,
        cashCollectionType : data.cashCollectionType,
        cashPumpingType : data.cashPumpingType,
        cashPumpingFee : data.cashPumpingFee,
        receivingAccountType : data.receivingAccountType,
        receivingAccountNumber : data.receivingAccountNumber,
        receivingMan : data.receivingMan,
        receivingManPhone : data.receivingManPhone,
        otherServiceName : data.otherServiceName,
        otherServiceType : data.otherServiceType,
        otherServiceUrl : data.otherServiceUrl,
        otherServiceDesc : data.otherServiceDesc,
        hasMidPage : data.hasMidPage,
    };
    if (editType != 'info' && (!Compare(checkData, oneIsvBizInfo))) {
        swalClosePageToastr(doBack);
        return;
    }
    doBack();
}